<?php
class Newsletter extends FrontEnd_Controller {
    function Newsletter(){
        parent::FrontEnd_Controller();
        $this->_data['erreur'] = "";
        $this->load->model('Newsletter_m');
     }
    function index(){

        $this->enregistrer();
    }
    function enregistrer(){
        $this->_data['page'] = "newletters";
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email|xss_clean');
        if($this->input->post('submit')){

        if ($this->form_validation->run()){
       if (!$this->Newsletter_m->is_existe($this->input->post('email'))){
           $this->Newsletter_m->add_email($this->input->post('email'));
           $this->_data['erreur'] = "Votre email a été enregistré !";
       } else {
            $this->_data['erreur'] = "Email existe déja !";
       }
            }
        }

        $this->display_view('home/newsletter');
    }
}
?>
